/*
Copyright (C) 2010  Christoph Schnack, Berlin (Germany)

This file is part of Tribuit.

    Tribuit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Tribuit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Tribuit.  If not, see <http://www.gnu.org/licenses/>.
*/
package PictureDescription;

import java.util.*;

import Settings.Settings;

/**
 * @author Christoph Schnack
 *
 */
public class PictureCollection {
	String name;
	Vector<PictureUnit> PICTURES;
	Settings SET;
	
	public PictureCollection(Settings set,String nameArg){
		name=nameArg;
		PICTURES = new Vector<PictureUnit>();
		SET=set;
	}
	
	public String getName(){
		return name;
	}
	
	public boolean hasPictures(){
		return PICTURES.size()>0;
	}
	
	public boolean hasPicture(String arg){
		if(PICTURES.size()>0){
			for(int i=0;i<PICTURES.size();i++){
				if(PICTURES.elementAt(i).getName().equals(arg))return true;
			}
		}
		return false;
	}
	
	public Vector<PictureUnit> getPictureUnits(){
		return PICTURES;
	}
	
	public PictureUnit getPictureUnit(String arg){
		if(PICTURES.size()>0){
			for(int i=0;i<PICTURES.size();i++){
				if(PICTURES.elementAt(i).getName().equals(arg))return PICTURES.elementAt(i);
			}
		}
		return null;
	}
	
	public void addPU(PictureUnit pu){
		PICTURES.add(pu);
	}
	
	public void deletePictureUnit(String pu){
		if(PICTURES.size()>0){
			for(int i=0;i<PICTURES.size();i++){
				if(PICTURES.elementAt(i).getName().equals(pu))PICTURES.removeElementAt(i);
			}
		}
	}
	
	public void replacePictureUnit(String old,PictureUnit pu){
		if(PICTURES.size()>0){
			for(int i=0;i<PICTURES.size();i++){
				if(PICTURES.elementAt(i).getName().equals(pu.getName())){
					PICTURES.removeElementAt(i);
					break;
				}
			}
			PICTURES.add(pu);
		}
	}
	
	public Vector<String> getSections(){
		Vector<String> sects = new Vector<String>();
		if(PICTURES.size()>0){
			String sect;
			for(int i=0;i<PICTURES.size();i++){
				sect = PICTURES.elementAt(i).getSection();
				if(!sects.contains(sect)) sects.add(sect);
			}
		}
		return sects;
	}
	
	public Vector<PictureUnit> getPictureUnitsOfSection(String section){
		Vector<PictureUnit> pics = new Vector<PictureUnit>();
		for(PictureUnit pu : PICTURES){
			if(pu.getSection().equals(section)) pics.add(pu);
		}
		return pics;
	}
	
	public void setName(String arg){
		if(arg!=null){
			arg=arg.trim();
			if(!arg.equals("")){
				name=arg;
			}
		}
	}

}
